﻿CloudDisk.Admin.AdminBoard = {
    header: $('#header'),
	nav: $('#nav'),
	body: $('#content')
};

(function(w){

    function init(){
	    this.nav.init();
		this.body.init();
	}
		
	function setActiveTab(tab){
	    this.nav.selectTab(tab);
		$('#content .adm-tab').hide();
		if(tab == 'profile'){
			CloudDisk.Admin.ProfilePanel.activate();
		} else if(tab == 'member'){
			CloudDisk.Admin.MemberPanel.activate();
		} else if(tab == 'groups'){
			CloudDisk.Admin.GroupsPanel.activate();
		} else if(tab == 'folders'){
			CloudDisk.Admin.FoldersPanel.activate();
		}  else if(tab == 'account'){
			CloudDisk.Admin.AccountPanel.activate();
		}  else if(tab == 'notification'){
			CloudDisk.Admin.NotificationPanel.activate();
		} 		
	}

    //public methods
	w.init = init;
	w.setActiveTab = setActiveTab;
})(CloudDisk.Admin.AdminBoard);

//main menu
(function(w){
    var el = this;
    var activeCls = 'nav-first-active';
    function init(){
	    this.click(function(e){
		    if($(e.target).hasClass('nav-first') && !$(e.target).hasClass(activeCls)){
			    $(this).find('.nav-first').removeClass(activeCls);
				$(e.target).addClass(activeCls); 
	 	        window.location.hash = "tab=" + e.target.getAttribute('tar');
			}	
		});
		
		//recursive fetch notifications
		function recursiveFetchNotifications(){
		    CloudDisk.Admin.SessionMgr.queryReceivedNotifications(function(data){		    
				var count = 0, result = data.result;
				for(var i = 0; i < result.length; ++i){
				    if(result[i].is_read != '1')count++;
				}
				w.find('DIV[tar=notification]').html('消息(' + count + ')');
				setTimeout(recursiveFetchNotifications, 300000);//fetch interval
			});
		}
		recursiveFetchNotifications();
	}
	
	function selectTab(tab){
	    $(this).find('.nav-first').removeClass(activeCls);
	    $(this).find('DIV[tar=' + tab + ']').addClass(activeCls); 
	}


    //public methods
	w.init = init;
	w.selectTab = selectTab;
})(CloudDisk.Admin.AdminBoard.nav);

//body
(function(w){
	
	function init(){
        $('.adm-tab').height($(window).height() - $('#header').height() - $('#navWrapper').height());
		$(window).resize(function(){
		    $('.adm-tab').height($(window).height() - $('#header').height() - $('#navWrapper').height());
		});
	}
    
	//public methods
	w.init = init;
})(CloudDisk.Admin.AdminBoard.body);